<?php

namespace Admin\Controller;

use Think\Controller;

class ExposurePackageController extends Controller {

    public function exposurePackageList() {
        $map = array();
        $package_name = trim(I('get.package_name'));
        //套餐名称搜索
        if ($package_name && $package_name != "") {
            $map['package_name'] = array('like', "$package_name%%");
        }
        $result = D("ExposurePackage")->exposurePackageList($map);
        $this->assign('exposurePackage', $result['comList']);
        $this->assign('page', $result['page']);
        $this->display();
    }

    /*
     * 云曝光套餐编辑
     * csb
     */

    public function exposurePackageEdit() {
        if (IS_POST) {
            $data = I("post.");
            $exposurePackageModel = D("ExposurePackage");
            $result = $exposurePackageModel->editData($data);
            if ($result) {
                $arr['status'] = 200;
                $arr['info'] = "操作成功";
            } else {
                $arr['status'] = 100;
                $arr['info'] = $exposurePackageModel->getError();
            }
            $this->ajaxReturn($arr);
        } else {
            $id = I('get.id');
            if ($id) {
                $exposurePackageinfo = D("ExposurePackage")->getDataById(array('id' => $id));
                $this->assign('exposurePackageinfo', $exposurePackageinfo);
            }
            $this->display();
        }
    }

    /*
     * 删除云曝光套餐
     * csb
     */
    public function exposurePackageDel() {
        $id = intval(I('post.id')) ? I('post.id') : 0;
        $num = M("exposure_order")->where(array("package_id" => $id))->count();
        if ($num > 0) {
            $arr['status'] = 100;
            $arr['info'] = "存在关联订单，无法删除";
        } else {
            $result = D("ExposurePackage")->deleteData(array('id' => $id));
            if ($result) {
                $arr['status'] = 200;
                $arr['info'] = "删除成功";
            } else {
                $arr['status'] = 100;
                $arr['info'] = "失败，请刷新重试".$id;
            }
        }
        $this->ajaxReturn($arr);
    }
}
